package com.bz.redis.service.impl;

import com.bz.pojo.TbItem;
import com.bz.pojo.TbItemDesc;
import com.bz.pojo.TbItemParamItem;
import com.bz.redis.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    private String frontend_item_basic_info_key = "frontend:item:basic:info:key;";

    private String frontend_item_desc_key = "frontend:item:desc:key";

    private String frontend_item_param_key = "frontend:item:param:key";

    /**
     * 缓存商品基本信息
     * @param tbItem
     */
    @Override
    public void insertItemBasicInfo(TbItem tbItem) {
        redisTemplate.opsForValue().set(frontend_item_basic_info_key+":"+tbItem.getId(),tbItem);
    }

    /**
     * 查询缓存中的商品基本信息
     * @return
     */
    @Override
    public TbItem selectItemBasicInfo(Long tbItemId) {
        return (TbItem)redisTemplate.opsForValue().get(frontend_item_basic_info_key+":"+tbItemId);
    }

    /**
     * 添加缓存商品介绍信息
     * @param tbItemDesc
     */
    @Override
    public void insertItemDesc(TbItemDesc tbItemDesc) {
        redisTemplate.opsForValue().set(frontend_item_desc_key+":"+tbItemDesc.getItemId(),tbItemDesc);
    }

    /**
     * 查询缓存中的商品介绍
     * @return
     */
    @Override
    public TbItemDesc selectItemDesc(Long tbItemId) {
        return (TbItemDesc) redisTemplate.opsForValue().get(frontend_item_desc_key+":"+tbItemId);
    }

    /**
     * 添加缓存商品的规格参数
     * @param tbItemParamItem
     */
    @Override
    public void insertItemParamItem(TbItemParamItem tbItemParamItem) {
        redisTemplate.opsForValue().set(frontend_item_param_key+":"+tbItemParamItem.getItemId(),tbItemParamItem);
    }

    /**
     * 查询缓存中的商品规格参数
     * @return
     */
    @Override
    public TbItemParamItem selectItemParamItem(Long tbItemId) {
        return (TbItemParamItem) redisTemplate.opsForValue().get(frontend_item_param_key+":"+tbItemId);
    }
}
